dnf install -y containerd.io kubelet kubeadm kubectl

#生成containerd配置文件
containerd config default > /etc/containerd/config.toml

# 修改 SystemdCgroup 参数为 true，表示 containerd 使用 systemd 作为 cgroup 驱动程序。
sed -ri 's#SystemdCgroup = false#SystemdCgroup = true#' /etc/containerd/config.toml

# 修改sandbox沙箱镜像，registry.k8s.io 在某些网络环境下可能访问不稳定或受到限制，
# 而阿里云的镜像仓库 registry.aliyuncs.com 在国内网络环境下通常具有更好的访问速度和稳定性。
sed -ri 's#registry.k8s.io\/pause:3.8#registry.aliyuncs.com\/google_containers\/pause:3.9#' /etc/containerd/config.toml

# 新增镜像源
sed -i 's/config_path = ""/config_path = "\/etc\/containerd\/certs.d\/"/g' /etc/containerd/config.toml

mkdir -p /etc/containerd/certs.d/docker.io

cat > /etc/containerd/certs.d/docker.io/hosts.toml << 'EOF'
server = "https://docker.io" # 源镜像地址

[host."https://docker.m.daocloud.io"] # 道客-镜像加速地址
  capabilities = ["pull","resolve"]

[host."https://dockerproxy.com"] # 镜像加速地址
  capabilities = ["pull", "resolve"]

[host."https://docker.hpcloud.cloud"] # 镜像加速地址
  capabilities = ["pull", "resolve"]

[host."https://docker.unsee.tech"] # 镜像加速地址
  capabilities = ["pull", "resolve"]

[host."https://docker.1panel.live"] # 镜像加速地址
  capabilities = ["pull", "resolve"]

[host."https://docker.chenby.cn"] # 镜像加速地址
  capabilities = ["pull", "resolve"]

[host."https://mirror.azure.cn"] # 镜像加速地址
  capabilities = ["pull", "resolve"]

[host."https://dockerpull.org"] # 镜像加速地址
  capabilities = ["pull", "resolve"]

[host."https://dockerhub.icu"] # 镜像加速地址
  capabilities = ["pull", "resolve"]

[host."https://hub.rat.dev"] # 镜像加速地址
  capabilities = ["pull", "resolve"]

[host."https://docker.mirrors.sjtug.sjtu.edu.cn"] # 上海交大-镜像加速地址
  capabilities = ["pull","resolve"]

[host."https://docker.mirrors.ustc.edu.cn"] # 中科大-镜像加速地址
  capabilities = ["pull","resolve"]

[host."https://docker.nju.edu.cn"] # 南京大学-镜像加速地址
  capabilities = ["pull","resolve"]

[host."https://registry.docker-cn.com"]
  capabilities = ["pull","resolve","push"]

[host."https://cf-workers-docker-io-38g.pages.dev"]
  capabilities = ["pull","resolve","push"]
EOF

# 启动底层容器运行时并开机自启动
systemctl enable containerd
systemctl start containerd



systemctl enable kubelet
